package it.lovaex.scb.unittests;

import static org.junit.Assert.*;

import java.math.BigDecimal;

import it.lovaex.scb.factory.BookFactory;
import it.lovaex.scb.model.BookItem;
import org.junit.Assert;
import org.junit.Test;

public class BookFactoryTest {

	String bookName = "bookName";
	String authorName = "a name for an author";
	BigDecimal bookPrice = new BigDecimal(100);
	
	@Test
	public void test_factory_create_book() {
		BookItem result = BookFactory.create(bookName, bookPrice);
		BookItem expected = new BookItem(bookName, bookPrice, "Unknown Author");
		assertEquals(result.getAuthor(), expected.getAuthor());
		assertEquals(result.getDescription(), expected.getDescription());
		assertEquals(result.getName(), expected.getName());
		assertEquals(result.getPrice(), expected.getPrice());
	}
	
	@Test
	public void test_factory_create_book_with_author() {
		BookItem result = BookFactory.create(bookName, bookPrice, authorName);
		BookItem expected = new BookItem(bookName, bookPrice, authorName);
		assertEquals(result.getAuthor(), expected.getAuthor());
		assertEquals(result.getDescription(), expected.getDescription());
		assertEquals(result.getName(), expected.getName());
		assertEquals(result.getPrice(), expected.getPrice());
	}

	@Test
	public void test_create_new_item_every_times(){
		BookItem first = BookFactory.create(bookName, bookPrice, bookName);
		BookItem second = BookFactory.create(bookName, bookPrice, bookName);
		Assert.assertNotEquals(first.hashCode(), second.hashCode());
	}
}
